import { saveHistorySearchList, saveIsFirst, saveIsOpenCamera } from '@/utils/localStorage'

/*
 * @Autor: Ruohong Yu
 * @Date: 2022-09-13 13:11:37
 * @Description: file content
 * @FilePath: \ebook\src\store\modules\store.js
 */
const store = {
  state: {
    hotSearchOffsetY: 0,
    flapCardVisible: false,
    isEditMode: false, // 编辑模式
    shelfList: [], // 书架列表
    shelfSelected: [], // 书架选中列表
    shelfTitleVisible: true, // 书架标题显示状态
    shelfCategory: [], // 书架分类列表
    currentType: 1, // 书架列表为1，书架分类列表为2
    suspendBallVisible: false, // 悬浮球是否可见
    isFirst: true,
    shelfType: 1, // 1：默认 2：私密阅读
    historySearchList: []
  },
  mutations: {
    SET_HOT_SEARCH_OFFSETY (state, y) {
      state.hotSearchOffsetY = y
    },
    SET_FLAP_CARD_VISIBLE (state, visible) {
      state.flapCardVisible = visible
    },
    SET_IS_EDIT_MODE (state, isEditMode) {
      state.isEditMode = isEditMode
    },
    SET_SHELF_LIST (state, list) {
      state.shelfList = list
    },
    SET_SHELF_SELECTED (state, selected) {
      state.shelfSelected = selected
    },
    SET_SHELF_TITLE_VISIBLE (state, visible) {
      state.shelfTitleVisible = visible
    },
    SET_SHELF_CATEGORY (state, category) {
      state.shelfCategory = category
    },
    SET_CURRENT_TYPE (state, type) {
      state.currentType = type
    },
    SET_SUSPEND_BALL_VISIBLE (state, visible) {
      saveIsOpenCamera(visible)
      state.suspendBallVisible = visible
    },
    SET_IS_FIRST (state, isFirst) {
      saveIsFirst(isFirst)
      state.isFirst = isFirst
    },
    SET_SHELF_TYPE (state, type) {
      state.shelfType = type
    },
    SET_HISTORY_SEARCH_LIST (state, list) {
      saveHistorySearchList(list)
      state.historySearchList = list
    }
  }
}

export default store
